<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Task extends CI_Controller {

	     public function __construct()
       {
            parent::__construct();
		$this->load->helper("html");
		$this->load->helper("url");
		$this->load->helper('form');
		$this->load->helper('date');
		$this->load->model("task_model");
		//$this->load->model("guest_comment_model");
		//$this->load->model("news_events_model");
		//$this->load->model("roomcottages_model");
		$this->load->helper(array('form', 'url'));
		$this->load->database();
		
	}
	
	//START ------------------dv---------------------
	function index()
	{
		$data['title']="Administrator Page";
		$data["list_tasks"] = $this->task_model->get_all_task();	
		$this->load->view('task_list_view',$data);
	}

	function SearchTaskFromTo()
	{
	$column_value=$_POST['column_value'];
	$data["column_value"]=$column_value;
	$data["list_tasks"]=$this->task_model->getSearchBytask($_POST['search_value'],$column_value);
	$this->load->view('task_list_view',$data);
	}
	function SearchTaskFromTo1221()
	{
	$search=$_POST['search'];
	$data["search"]=$search;
	$data["list_tasks"]=$this->task_model->getdvSearchBytask($search);
	$this->load->view('task_list_view',$data);
	}
	
	function view_task()
	{
	    $code = $this->uri->segment(3);
		$data["info"] = $this->task_model->gettask_info($code);	
		$this->load->view('task_file_view',$data);
		
	}
	
	function add_task()
	{
		//$data["driver_dv_data"] = $this->dv_model->add_view_driver_dv();
		$this->load->view('task_add_view');
	}
	function p_add_task()
	{
		
	 //echo"sulod sa function";
		
		if(isset($_POST['cmdUpload']))
		{
			$this->load->database();
			$config['upload_path'] = 'upload';
			$config['allowed_types'] = 'gif|jpg|png|pdf|one';
			$config['max_size']	= '';
			$config['max_width']  = '';
			$config['max_height']  = '';
			$config['encrypt_name'] = FALSE;
			$config['overwrite'] = FALSE;
			$config['remove_spaces'] = true;
			
			//echo"ni sulod sa cmd upload";
			
			$this->load->library('upload', $config);
		
			if ( ! $this->upload->do_upload())
			{
				$error = array('error' => $this->upload->display_errors());
  				$file_name = 0;
			}	
			else
			{
				$data = array('upload_data' => $this->upload->data());
				$file_name = $this->upload->file_name;
			}
			$pdf = $file_name;	
		$path = my_url()."upload/$pdf";
	//echo"$path";
		$title =$_POST['txttitle'];
		$t_from =$_POST['txtt_from'];
		$t_to =$_POST['txtt_to'];
		$date =$_POST['txtdate'];
		$description =$_POST['txtdescription'];
		$c_date=$_POST['txtc_date'];		
		
		$_sql="insert into task(title,t_from,t_to,date,description,c_date,t_pdf_path)";
		$_sql.="values('$title','$t_from','$t_to','$date','$description','$c_date','$path')";
		
		$query = $this->db->query($_sql); 
			if($query)
				{
				$data['recordflag']="<img src='".my_url()."images/icons/success.gif' />
				Successfully Added.";
				}
				else{
				$data['recordflag']="<img src='".my_url()."images/icons/error.gif' />
				 Error on Saving Data.";
				}
	/*	$dv_id=$this->db->insert_id();
	 
		$_sql="insert into dv_contract(dv_id,contract_amount)";
		$_sql.="values($dv_id,$contract_amt)";
		$query = $this->db->query($_sql); */
		
			
		$data["list_tasks"] = $this->task_model->get_all_task();	
		
		$this->load->view('task_list_view',$data);
	}						
	}

	function edit_task()
	{
 	    $code = $this->uri->segment(3);
		$data["info"] = $this->task_model->gettask_info($code);	
		$this->load->view('task_edit_view',$data);
	}
	function p_edit_task()
	{
	    //echo"sulod sa function";
		
		if(isset($_POST['cmdUpload']))
		{
			$this->load->database();
			$config['upload_path'] = 'upload';
			$config['allowed_types'] = 'gif|jpg|png|pdf|.one';
			$config['max_size']	= '';
			$config['max_width']  = '';
			$config['max_height']  = '';
			$config['encrypt_name'] = FALSE;
			$config['overwrite'] = FALSE;
			$config['remove_spaces'] = true;
			
			//echo"ni sulod sa cmd upload";
			
			$this->load->library('upload', $config);
		
			if ( ! $this->upload->do_upload())
			{
				$error = array('error' => $this->upload->display_errors());
				$file_name = 0;
				
			}	
			else
			{
				$data = array('upload_data' => $this->upload->data());
				$file_name = $this->upload->file_name;
			}

		$pdf = $file_name;	
		$path = my_url()."upload/$pdf";
		$this->load->database();
	    $task_id= $_POST['hid_id'];
		$title =$_POST['txttitle'];
		$t_from =$_POST['txtt_from'];
		$t_to =$_POST['txtt_to'];
		$date =$_POST['txtdate'];
		$description =$_POST['txtdescription'];
		$c_date=$_POST['txtc_date'];

		$query = $this->db->query("UPDATE task SET 
												  		  title='$title', 
														  t_from='$t_from',
														  t_to='$t_to',														  														  
														  date='$date',														  														  
														  description='$description',														  														  
														  c_date='$c_date',
														  t_pdf_path='$path'
														   where task_id=$task_id");
			if($query)
				{
				$data['recordflag']="<img src='".my_url()."images/icons/success.gif' />
				Successfully Updated.";
				}
				else{
				$data['recordflag']="<img src='".my_url()."images/icons/error.gif' />
				 Error on Updating Data.";
				}
																  
		$data["list_tasks"] = $this->task_model->get_all_task();	
		$this->load->view('task_list_view',$data);		
	}
	}
	function p_view_task()
	{
	    //echo"sulod sa function";
		
		if(isset($_POST['cmdUpload']))
		{
			$this->load->database();
			$config['upload_path'] = 'upload';
			$config['allowed_types'] = 'gif|jpg|png|pdf|one';
			$config['max_size']	= '';
			$config['max_width']  = '';
			$config['max_height']  = '';
			$config['encrypt_name'] = FALSE;
			$config['overwrite'] = FALSE;
			$config['remove_spaces'] = true;
			
			//echo"ni sulod sa cmd upload";
			
			$this->load->library('upload', $config);
		
			if ( ! $this->upload->do_upload())
			{
				$error = array('error' => $this->upload->display_errors());
				$file_name = 0;
				
			}	
			else
			{
				$data = array('upload_data' => $this->upload->data());
				$file_name = $this->upload->file_name;
			}

		$pdf = $file_name;	
		$path = my_url()."upload/$pdf";
		$this->load->database();
	    $task_id= $_POST['hid_id'];
		$title =$_POST['txttitle'];
		$t_from =$_POST['txtt_from'];
		$t_to =$_POST['txtt_to'];
		$date =$_POST['txtdate'];
		$description =$_POST['txtdescription'];
		$c_date=$_POST['txtc_date'];
		$t_pdf_path =$_POST['t_pdf_path'];
		
		$query = $this->db->query("UPDATE task SET 
												  		  title='$title', 
														  t_from='$t_from',
														  t_to='$t_to',														  														  
														  date='$date',														  														  
														  description='$description',														  														  
														  c_date='$c_date',
														  t_pdf_path='$path',
														  t_pdf_path='$t_pdf_path'
														   where task_id=$task_id");
			if($query)
				{
				$data['recordflag']="<img src='".my_url()."images/icons/success.gif' />
				Successfully Updated.";
				}
				else{
				$data['recordflag']="<img src='".my_url()."images/icons/error.gif' />
				 Error on Updating Data.";
				}
																  
		$data["list_tasks"] = $this->task_model->get_all_task();	
		$this->load->view('task_list_view',$data);		
	}
	}
	
	function delete_task()
	{
		$this->load->database();		
		$code = $this->uri->segment(3);
		$query = $this->db->query("delete from profile where profile_id='$code'");
		
		$data["list_tasks"] = $this->task_model->get_all_task();	
		$this->load->view('task_list_view',$data);
	}
	//END ------------------dv---------------------
	
	
	function logout()
	{
		
		//$this->load->library('session');
		//$this->session->sess_destroy();
		session_start();
		session_destroy();
		//echo $_SESSION['Administrator_log'];
		//unset($_SESSION['Administrator_log']);
		
			//$data["newsresult"] = $this->dv_model->dv_all_driver_dv();
			$this->load->view('admin_view');
	 
	}
 
}
?>